/*
 * play_thread.cpp
 *
 *  Created on: 2014-8-22
 *      Author: iot
 */

#include "GTKView.h"
#include "uaserver.h"

#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

#include "FfmpegPlayer.h"



__namespace_bjp_start__
static unsigned char* pic_buf;
static int gtk_width;
static int gtk_height;

void fMapMemoryCB(void** opaque, int* width, int* height)
		{
//	src_buf = (guchar*)malloc(width * height * 3);
	*width = gtk_width;
	*height = gtk_height;
*opaque = (void*)pic_buf;

		}

//void* play_thread_routine(void* arg)
//{
//		UserData* pUser = (UserData*)arg;
////		gtk_widget_set_size_request(pUser->image, width, height);
////		pic_buf = gdk_pixbuf_get_pixels(pUser->buf);
////		gtk_width = gdk_pixbuf_get_width(pUser->buf);
////		gtk_height = gdk_pixbuf_get_height(pUser->buf);
//
////FfmpegPlayer* player = CreatePlayerInstance();
////MapMemoryCB cb = fMapMemoryCB;
////SetMapMemoryCallBack(player, cb);
////PlayRTPStream(player, atoi(UAServer::config.play_port.c_str()));
////PlayNormalFile(player, "/home/iot/video/5.flv");
////SaveRTPStream(player, atoi(UAServer::config.play_port.c_str()), "/home/lewis/Desktop/1.dat");
//
////while(1)
////{
////	usleep(100000);
////	gtk_widget_queue_draw(pUser->image);
////
////}
//
//
////	FILE* fd = fopen("/home/iot/Desktop/28181.264","a");
////
////
////	struct sockaddr_in addr;
////	addr.sin_family = AF_INET;
////	addr.sin_port = htons(6000);
////	addr.sin_addr.s_addr = htonl(INADDR_ANY);
////
////	struct sockaddr_in sendAddr;
////	sendAddr.sin_family = AF_INET;
////	sendAddr.sin_port = htons(6090);
////	sendAddr.sin_addr.s_addr = htonl(INADDR_ANY);
////
////	int recvSock;
////	if ( (recvSock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
////	{
////		perror("recvSocket");
////		exit(1);
////	}
////	int sendSock;
////	if ( (sendSock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
////	{
////		perror("sendSock");
////		exit(1);
////	}
////
////	if (bind(sendSock, (struct sockaddr *)&sendAddr, sizeof(sendAddr)) < 0)
////	{
////		perror("bind");
////		exit(1);
////	}
////	if (bind(recvSock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
////	{
////		perror("bind");
////		exit(1);
////	}
////	char buff[2048];
////	struct sockaddr_in clientAddr;
////
////	struct sockaddr_in serverAddr;
////	serverAddr.sin_family = AF_INET;
////	serverAddr.sin_port = htons(7090);
////	serverAddr.sin_addr.s_addr = (inet_addr("192.168.51.25"));
////	int n;
////	socklen_t len = sizeof(clientAddr);
////	while (1)
////	{
////		n = recvfrom(recvSock, buff, 2047, 0, (struct sockaddr*)&clientAddr, &len);
////		if (n>0)
////		{
////			n = sendto(sendSock, buff, n, 0, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
//////			perror("sendto");
////			printf("%d\n", n);
////			//buff[n] = 0;
////			//printf("%s %u says: %s\n", inet_ntoa(clientAddr.sin_addr), ntohs(clientAddr.sin_port), buff);
////		}
////
////
////	}
//}
//
__namespace_bjp_end__
